#include<stdio.h>//984
#include<stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
typedef struct node
{
	char data;
	node *lchild,*rchild;
}BiNode,*BiTree;
void CreatBiTree(BiTree &T,char mid[],char pre[],int len)
{
	if (len <= 0){ T = NULL; return; }
	char root, *p; int index;
	root = *pre;
	T=(BiTree)malloc(sizeof(BiNode));
		T->data=root;
		for (p = mid; p < mid + len; p++)
		{
			if (*p == root)
			{
				index = p - mid; break;
			}
		}
		CreatBiTree(T->lchild,mid,pre+1,index);
		CreatBiTree(T->rchild,p+1,pre+index+1,len-index-1);
}
void dispaly(BiTree T)
{
	if(T!=NULL)
	{		
		dispaly(T->lchild);
		dispaly(T->rchild);
		cout<<T->data;
	}
}
int main()
{
	char mid[1000],pre[1000];
	cin>>mid>>pre;
	BiTree T;
	T=(BiTree)malloc(sizeof(BiNode));
	int len = strlen(mid);
	CreatBiTree(T,mid,pre,len);
	dispaly(T);
	return 0;
}